/**
 * Created by lixiaodi on 2018/11/10.
 */
mini.parse();
//得到数据表
var grid = mini.get("dataGrid");
grid.load(ajaxUrl + "/ReportParamController/FindReportlist.do");
grid.load();
//增加
function add(){
    var configureObj = {
        data : {action: "new"},
        url : bootPATH + '../frame/frame1/pages/reportForm/dataSources.html',
        title : "新增数据来源",
        width: 600,
        height:700
    }
    openChild(configureObj);
}
//编辑
function edit(){
    //得到被选中的报表id
    var row = grid.getSelected();
    if(row){
        var configureObj = {
            title : "编辑数据来源",
            data : {action: "edit",reportId : row.reportId},
            url : bootPATH + '../frame/frame1/pages/reportForm/dataSources.html',
            width: 600,
            height:700
        }
        openChild(configureObj);
    }else{
       mini.alert("请选择一条");
    }
}
//删除
function remove() {
    var row = grid.getSelected();
    if (row) {
        mini.confirm("确定删除选中记录？","系统提示",function(action){
            if (action == "ok") {
                var reportIds = row.reportId;
                grid.loading("操作中，请稍后......");
                $.ajax({
                    url: ajaxUrl + "/ReportParamController/deleteReportParam.do?id=" + reportIds,
                    type:"post",
                    success: function (text) {
                        grid.reload();
                    },
                    error: function () {
                        mini.alert('失败');
                    }
                });
            }
        })
    } else {
        mini.alert("请选中一条记录");
    }
}
//查询
function search(){
    var row = grid.getSelected();
    if (row) {
        var reportIds = row.reportId;
        window.location.href = "reportForm.html?reportId=" + reportIds;
        //grid.loading("操作中，请稍后......");
        //$.ajax({
        //    url: "http://192.168.178.103:8080/report/reportController/list.do?reportId=" + reportIds,
        //    type:"post",
        //    success: function (data) {
        //        console.log(data);
        //        //grid.reload();
        //    },
        //    error: function () {
        //        mini.alert('失败');
        //    }
        //});
    } else {
        mini.alert("请选中一条记录");
    }
}
//打开子页面
function openChild(configureObj){
    mini.open({
        url        : configureObj.url,
        title      : configureObj.title,
        width      : configureObj.width,
        height     : configureObj.height,
        onload     : function(){
            var iframe = this.getIFrameEl();
            //用data.action判断是新增页面还是编辑页面
            var data = configureObj.data;
            iframe.contentWindow.SetData(data);
        },
        ondestroy  : function(){
            grid.reload();
        }
    });
}

function treeMoMe(){
	var row = grid.getSelected();
	 if(row){
	        var configureObj = {
	            title : "关联菜单",
	            data : {action: "treeMoMe",reportId : row.reportId},
	            url : bootPATH + '../frame/frame1/pages/reportForm/treeMoMe.html',
	            width: 600,
	            height:400
	        }
	        openChild(configureObj);
	    }else{
	       mini.alert("请选择一条");
	 }
}


